﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.Revit;

namespace YArchitech.HVAC
{
	[Transaction(TransactionMode.Manual)]
	public class HYLayerBrush : HYNoTranExternalCommand
	{
		public override void FilterProcess()
		{
            base.FilterViewType.Add((ViewType)3);
            base.FilterViewType.Add((ViewType)4);
			base.FilterProcess();
		}

		public override Result HYExecute()
		{
			Reference reference = base.Sel.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "请选择基准实体……");
			Element element = base.Doc.GetElement(reference);
			IList<Element> list = base.Sel.PickElementsByRectangle(new LayerBrushFilter(element), "请框选要修改的实体……");
			while (list.Count < 1)
			{
				YJKMessageBox.Show("没有选中任何实体，请重新选择。");
				list = base.Sel.PickElementsByRectangle(new LayerBrushFilter(element), "请框选要修改的实体……");
			}
			RevitVersionFuncs.SetSelection(base.UiDoc.Selection, list as List<Element>);
			if (new LayerBrushSetting().GetParametersName(element, list).Count < 1)
			{
				YJKMessageBox.Show("选择实体集合与基准实体\n没有相同可修改属性！");
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			new FrmLayerBrush(element, list, base.Doc).ShowDialog();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public override void TailProcess()
		{
            if (this.tran != null && (int)this.tran.GetStatus() != 3)
			{
				this.tran.RollBack();
			}
		}

		private Transaction tran;
	}
}
